/**
 * <p>自定义form（单表模式），默认拥有“关闭”按钮</p>
 * <p>单表模式以form的形式提交</p>
 * xtype = cceafformpanel

 * @module Ext-ux-cceaf-control
 * @class cceaf.control.FormPanel
 * @extends Ext.form.Panel
 * @since 1.0
 */
Ext.define('cceaf.control.FormPanel',{
	extend: 'Ext.form.Panel', 
    alias: 'widget.cceafformpanel',
    requires: [
        'cceaf.control.FieldSet',
        'cceaf.control.Button'
    ],

	constructor: function(config){
		config = config || {};
        
		cceaf.control.FormPanel.superclass.constructor.apply(this, arguments);
	},
	
	/**
	 * 操作按钮定义区
	 *
     * @property operateArea 
     * @type Object[]
     * @default null
     */
    operateArea: null,
    
    /**
	 * 操作按钮布局方式：<p>
	 * standard：默认标准方式，按钮在最底部居中布局<p>
	 * bottom:toolbar的底部布局，按钮左对其<p>
	 * top:toolbar的顶部布局，按钮右对其<p>
	 *
     * @property buttonLayout 
     * @type String
     * @default 'standard'
     */
    buttonLayout: 'standard',
    
    /**
	 * 保存的action
	 * 如果没定义该值，保存按钮不可见
	 *
     * @property saveAction 
     * @type String
     * @default null
     */
    saveAction: null,
    
    /**
	 * 是否有关闭按钮
	 *
     * @property hasClose 
     * @type Boolean
     * @default true
     */
    hasClose: true,
    
    /**
	 * 主键集合，如"deptid,deptname"
	 * 提交后页面需要重新载入时，需要设置
	 * 
     * @property masterkeys 
     * @type String
     * @default null
     */
    masterKeyIds: null,
    
    /**
	 * 获取对象的action
	 * 提交后页面需要重新载入时，需要设置
	 * 
     * @property findByKeyAction 
     * @type String
     * @default null
     */
    findByKeyAction: null,
 	
    /**
	 * 主从表模式时，子表grid的itemId
	 * 
     * @property detailItemId 
     * @type String
     * @default 'detail'
     */
    detailItemId: 'detail',
    
    /**
	 * 主表json中子表集名称
	 * 
     * @property masterkeys 
     * @type String
     * @default null
     */
    details: null,
    
	initComponent : function(){
		var config = this;
		
		var layout = config.layout;
		var columns = config.columns;
		if(columns != null){
        	layout = {
	        	type: 'table',
	        	columns: columns
	        };
        	config = Ext.apply(config, {layout: layout});
        }
        
        var operateArea = [],i=0;
		if (config.operateArea) {
			operateArea = config.operateArea;
		} else { //默认操作区
			{
				if (config.saveAction) {
					operateArea[i] = {itemId:'btnSave', xtype: 'cceafbutton', text: '保存', iconCls: 'acceptIcon'};
					i++;
				}
				if (config.hasClose) {
					operateArea[i] = '-';
					i++;
					operateArea[i] = {itemId: 'btnClose', xtype: 'cceafbutton', text: '关闭', iconCls: 'closeIcon'};
					i++;
				}
			}
		}
		
		var buttonLayout = config.buttonLayout;
		var buttons;
		var dockedItems;
		if (buttonLayout == 'standard') {
			buttons = operateArea;
		} else if (buttonLayout == 'bottom') {
			dockedItems = [{
	            xtype: 'toolbar',
	            dock: 'bottom',
	            border: true,
	            layout: { pack: 'end'},
	            items: operateArea
	        }];
		} else if (buttonLayout == 'top') {
			dockedItems = [{
	            xtype: 'toolbar',
	            dock: 'top',
	            border: true,
	            items: operateArea
	        }];
		}
		
        Ext.applyIf(this, {
        	bodyStyle: 'padding:10px 10px',
        	waitMsgTarget: true,
	        autoScroll:true,
	        //buttonAlign: 'center',
	        defaults:{  
	        	//bodyStyle:'padding:0px 5px 0px 0px',
    			layout: {
			        type: 'hbox',
			        align: 'middle'
			    },
    			baseCls:'x-plain',
    			padding: '5 5 5 5',
    			xtype:'cceaffieldset'
            },
            
	        buttons: buttons,
	        dockedItems: dockedItems
		});
		
		cceaf.control.FormPanel.superclass.initComponent.call(this);
    }
	
});